package com.sharemarking.application.common.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sharemarking.application.common.entity.Employee;
import com.sharemarking.application.common.repository.EmployeeRepo;




@Controller
@RequestMapping("phone")

public class EmployeeCon  {
	
	@Autowired
	private EmployeeRepo dao;
	
	@RequestMapping(value="getAllEmp")
	@ResponseBody
	public List<Employee> getAllEmployee(Employee e,Integer empid){
		List<Employee> list=new ArrayList<Employee>();
		Employee Emp=dao.findOne(empid);
		if(Emp.getCompanyId()!=null){
			list=(List<Employee>)dao.findAll();
			for(int i=0;i<list.size();i++){
				if(list.get(i).getJob()=="暂无"||list.get(i).getJob().equals("暂无")){
					list.remove(list.get(i));
				}
				//System.out.println(list.get(i).getId());
			}
		}
		list.remove(Emp);//删除自己
		return list;

		
	}
	
	@RequestMapping(value="findEmp") 
	@ResponseBody
	public Employee findEmp(Integer id){
		Employee emp=dao.findOne(id);
		return emp;
	}
	
	@RequestMapping(value="joinCom") 
	@ResponseBody
	public String joinCom(Integer id){
		Employee emp=dao.findOne(id);
		emp.setCompanyId(1);
		emp.setJob("普通员工");
		dao.save(emp);
		
	return "ok";
	}
}
